//
//  SaoMiaoResultController.m
//  药品通_石小强
//
//  Created by shixiaoqiang on 16/1/14.
//  Copyright © 2016年 shixiaoqiang. All rights reserved.
//

#import "SaoMiaoResultController.h"
#import "UIView+Frame.h"
@interface SaoMiaoResultController ()

@end

@implementation SaoMiaoResultController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createNavigationBar];
    
    UILabel *resultLabel = [[UILabel alloc] init];
    resultLabel.backgroundColor = [UIColor clearColor];
    resultLabel.text = @"未找到该条形码的药品，管理员确认后将收录！你也可以通过外包装上的批准文号查找！";
    resultLabel.textAlignment = NSTextAlignmentCenter;
    resultLabel.numberOfLines = 2;
    resultLabel.textColor = [UIColor blackColor];
    resultLabel.frame = CGRectMake(10, 100, WIDTH - 20, 50);
    [self.view addSubview:resultLabel];
    
    
    UITextField *resultField = [[UITextField alloc] init];
    resultField.frame = CGRectMake(10, 160, WIDTH - 90, 30);
    resultField.backgroundColor = [UIColor whiteColor];
    resultField.textColor = [UIColor grayColor];
    UIImageView *searchIcon = [[UIImageView alloc] init];
    searchIcon.image = [UIImage imageNamed:@"homepage_search"];
    searchIcon.size = CGSizeMake(25, 25);
    searchIcon.contentMode = UIViewContentModeCenter;
    resultField.leftView = searchIcon;
    resultField.leftViewMode = UITextFieldViewModeAlways;
    resultField.layer.cornerRadius = 15.0;
    resultField.layer.borderWidth = 1.0;
    resultField.layer.borderColor = [UIColor grayColor].CGColor;
    resultField.placeholder = @"如:国药准字H1234556";
    [resultField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:resultField];
    
    
    UIButton *resultBtn = [[UIButton alloc] init];
    resultBtn.frame = CGRectMake(WIDTH - 70, 160, 60, 30);
    [resultBtn setTitle:@"查询" forState:UIControlStateNormal];
    [resultBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    resultBtn.layer.borderWidth = 1.0;
    resultBtn.layer.cornerRadius = 15.0;
    [resultBtn setBackgroundColor:[UIColor blueColor]];
    [resultBtn addTarget:self action:@selector(resultBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:resultBtn];
}

- (void)resultBtnClick {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"没有找到相应的药品信息，请输入正确的批准文号" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)textFieldDidChange:(id)sender {
    UITextField *field = (UITextField *)sender;
    NSLog(@"%@",field.text);
}

/**
 *  设置导航栏
 */
- (void)createNavigationBar {
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navBg"]];
    UIButton *leftBtn = [[UIButton alloc] init];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    leftBtn.size = leftBtn.currentBackgroundImage.size;
    [leftBtn addTarget:self action:@selector(navBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    UILabel *title = [[UILabel alloc] init];
    title.text = @"没有结果";
    title.textColor = [UIColor whiteColor];
    title.size = CGSizeMake(60, 30);
    self.navigationItem.titleView = title;
}

/**
 *  导航栏返回按钮点击事件
 */
- (void)navBtnClick {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
